// https://www.programmercarl.com/0142.%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8II.html
// https://leetcode.cn/problems/linked-list-cycle-ii/description/

const detectCycle = function(head) {
    if (!head ||!head.next) return null;
    let slow = head.next;
    let fast = head.next.next;
    while (fast && fast.next) {
      fast = fast.next.next;
      slow = slow.next;
      if (fast === slow) {
        slow = head;
        while (slow !== fast) {
          slow = slow.next;
          fast = fast.next;
        }
        return slow;
      }
    }    
    return null;  
};